#!/bin/bash

remote_server="root@116.62.79.131"
remote_directory="/usr/ops/lib/node1/"

# 循环遍历每个文件
for file in *.jar; do
  # 判断远程服务器上文件是否存在
  ssh $remote_server "[ -f $remote_directory$file ]"
  if [ $? -eq 0 ]; then
    # 部署项目
    if [[ $file != *gateway* ]]; then
      new="${file%-*} ${file##*-}"
      new="${new%.jar}"
      ssh $remote_server "cd /usr/ops && sh /usr/ops/deploy-service.sh node1 $new"
    fi
  fi
done

read -n 1 -s -r -p $'\n'"Press any key to exit"